package com.dljd.javase.t11.output;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedOutputStreamDemo {
    public static void main(String[] args)  throws Exception{
        //noBufferDemo();
        bufferDemo();
    }

    public static void noBufferDemo() throws IOException, InterruptedException {
        FileOutputStream bo=new FileOutputStream("D:/123123.txt");
        bo.write(97);
        Thread.sleep(2000);
        bo.write(98);
        Thread.sleep(2000);
        bo.write(99);
        Thread.sleep(2000);
        bo.write(100);
        Thread.sleep(2000);
        bo.write(101);
        Thread.sleep(2000);
        bo.write(102);
        Thread.sleep(2000);
        bo.close();
    }

    public static void bufferDemo() throws IOException, InterruptedException {
        FileOutputStream fout=new FileOutputStream("D:/123123.txt");
        BufferedOutputStream bo=new BufferedOutputStream(fout);
        bo.write(97);
        Thread.sleep(2000);
        bo.write(98);
        Thread.sleep(2000);
        bo.write(99);
        bo.flush();
        Thread.sleep(2000);
        bo.write(100);
        Thread.sleep(2000);
        bo.write(101);
        Thread.sleep(2000);
        bo.write(102);
        Thread.sleep(2000);
        bo.close();
        fout.close();
    }
}
